#ifndef VIDEOENCODE_H
#define VIDEOENCODE_H

#define DEF_MPP_EN

#include <QDebug>
#include <cstring>
#include <malloc.h>
#include <QString>
#include <jpeglib.h>

#include "video.h"

//===============================VPU=========================
#ifndef DEF_MPP_EN
#include <rockchip/vpu_api.h>
#include <rockchip/rk_mpi.h>

#define BSWAP32(x) \
    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
     (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))

#else
//===============================MPP=========================
#include <rockchip/vpu_api.h>
#include <rockchip/rk_mpi.h>
#include <rockchip/rk_mpi_cmd.h>
#include <rockchip/rk_type.h>
#include <rockchip/mpp_buffer.h>
#include <rockchip/mpp_frame.h>
#include <rockchip/mpp_packet.h>
#include <rockchip/mpp_err.h>

#define ACCESS              access
#define MKDIR(a)            mkdir((a),0755)
#define MPP_ALIGN(x, a)     (((x)+(a)-1)&~((a)-1))

struct MPP_ENC_DATA
{
    // global flow control flag
    uint32_t frm_eos;
    uint32_t pkt_eos;
    uint32_t frame_count;
    uint64_t stream_size;

    // base flow context
    MppCtx ctx;
    MppApi *mpi;
    MppEncPrepCfg prep_cfg;
    MppEncRcCfg rc_cfg;
    MppEncCodecCfg codec_cfg;

    // input / output
    MppBufferGroup buf_grp;
    MppBuffer frm_buf;
    MppBuffer pkt_buf;
    MppEncSeiMode sei_mode;

    uint32_t width;
    uint32_t height;
    uint32_t hor_stride;
    uint32_t ver_stride;
    MppFrameFormat fmt;
    MppCodingType type;

    // resources
    size_t frame_size;

    int32_t gop;
    int32_t fps;
    int32_t bps;
};

#endif

namespace VideoEncode
{
    bool isOpen(void);
    bool open(const QString & file, int w, int h, int rate);
    void close(void);
    bool write(void * buff, int bufSize);

    int initMpp();
    void destroyMpp();
}

#endif // VIDEOENCODE_H
